import { defineConfig } from "vite";
import ViteComponents, { ElementPlusResolver  } from "vite-plugin-components";
import { viteMockServe } from 'vite-plugin-mock'
import viteCompression from "vite-plugin-compression";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    ViteComponents({
      customComponentResolvers: [ElementPlusResolver()],
    }),
    // gzip压缩 生产环境生成 .gz 文件
    viteCompression({
      verbose: true,
      disable: false,
      threshold: 10240,
      algorithm: "gzip",
      ext: ".gz",
    }),
    viteMockServe({
      injectCode: `
        import { setupProdMockServer } from './mockProdServer';
        setupProdMockServer();
      `,
      logger: true,
    }),
  ],
  server: {
    open: true
  },
  // 生产环境打包配置
  //去除 console debugger
  build: {
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
});
